import java.util.Stack;

public class Calculate {
    public int calculate(String s) {
        Stack<Integer> stack = new Stack<>();
        char op = '+';
        int index = 0;
        while (index < s.length()) {
            char c = s.charAt(index);
            if (c == ' ') {
                index++;
                continue;
            }
            if (c == '+' || c == '-' || c == '*' || c == '/') {
                op = c;
                index++;
            } else {
                int num = 0;
                while (index < s.length() && s.charAt(index) >= '0' && s.charAt(index) <= '9') {
                    num = num * 10 + (s.charAt(index) - '0');
                    index++;
                }
                if (op == '-') {
                    num = -num;
                } else if (op == '*') {
                    num = stack.pop() * num;
                } else if (op == '/') {
                    num = stack.pop() / num;
                }
                stack.add(num);
                op = '+';
            }
        }
        int ret = 0;
        while (!stack.isEmpty()) {
            ret += stack.pop();
        }
        return ret;
    }

    public static void main(String[] args) {
        String s = " 3+5 / 2 ";
        Calculate cal = new Calculate();
        System.out.println(cal.calculate(s));
    }
}
